<!doctype html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>发起核查</title>
    <script src="/webjars/miniui/boot.js" type="text/javascript"></script>
    <link href="/static/css/resource.css" rel="stylesheet" type="text/css" />
    <script src="/static/js/common/common.js" type="text/javascript"></script>
    <link href="/webjars/miniui/css/demo.css" rel="stylesheet" type="text/css" />
    <link href="/static/css/default.css" rel="stylesheet" type="text/css" />
    <style>
        .discell {
            text-align:right;
            width:140px;
        }
    </style>
</head>
<body>
<div class="mini-fit" style="margin-bottom:40px">
    <form id="form1" method="post" style="height:100%;width: 100%;overflow-x: auto;overflow-y: auto;">
        <!-- 编辑框START-->
        <div id="editform" class="form" style="padding:10px;">
            <table class="form-table" align="center" style="width: 80%;margin-left: 50px;" cellspacing="8">
                <#if paramMap.isPlhc=='false'>
                    <tr>
                        <td class="discell">服刑人员姓名:</td>
                        <td>
                            <input name="name" id="name" class="mini-textbox" value="${paramMap.pname!''}" style="width: 100%" readonly />
                        </td>

                        <td class="discell">性别:</td>
                        <td>
                            <input name="sex" id="sex" class="mini-textbox" value="${paramMap.sex!''}" style="width: 100%" readonly />
                        </td>
                    </tr>
                    <tr>
                        <td class="discell">户籍地址:</td>
                        <td colspan="3">
                            <input name="name" id="name" class="mini-textbox" value="${paramMap.nativeName!''}" style="width: 100%" readonly />
                        </td>
                    </tr>
                    <#if paramMap.hjType=='02'>
                        <tr>
                            <td class="discell">原侦查机关所在地:</td>
                            <td colspan="3">
                                <input name="name" id="name" class="mini-textbox" value="${paramMap.investigate!''}" style="width: 100%" readonly />
                            </td>
                        </tr>
                    </#if>
                    <tr>
                        <td class="discell">刑期起日:</td>
                        <td>
                            <input name="name" id="name" class="mini-textbox" value="${paramMap.rjDate!''}" style="width: 100%" readonly />
                        </td>

                        <td class="discell">刑期止日:</td>
                        <td>
                            <input name="sex" id="sex" class="mini-textbox" value="${paramMap.cjDate!''}" style="width: 100%" readonly />
                        </td>
                    </tr>
                </#if>
                <tr>
                    <td class="discell"><font color="#dc143c">*</font>发起核查人员姓名:</td>
                    <td>
                        <input name="startCheckPerson" id="startCheckPerson" class="mini-textbox" value="${paramMap.startCheckPerson!''}"
                               style="width: 100%" required="true" />
                    </td>
                    <td class="discell"><font color="#dc143c">*</font>发起核查时间:</td>
                    <td>
                        <input name="startCheckTime" id="startCheckTime" class="mini-datepicker" nullValue="null" format="yyyy-MM-dd H:mm:ss"
                               timeFormat="H:mm:ss" showTime="true"
                               showOkButton="true" enabled="false" showClearButton="false" allowInput="true" value="${paramMap.startCheckTime!''}"
                               style="width: 100%" required="true" />
                    </td>
                </tr>
                <tr>
                    <td class="discell">发起核查人员固话:</td>
                    <td>
                        <input name="startCheckTel" id="startCheckTel" class="mini-textbox" value="${paramMap.startCheckTel!''}" style="width: 100%"
                               emptyText="请输入固定电话" onvaluechanged="checkPhone(1)" />
                    </td>
                    <td class="discell">发起核查人员手机号码:</td>
                    <td>
                        <input name="startCheckPhone" id="startCheckPhone" class="mini-textbox" value="${paramMap.startCheckPhone!''}"
                               style="width: 100%"
                               emptyText="请输入手机号码" onvaluechanged="checkPhone(2)" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <input class="mini-hidden" id="checkUser" value="${paramMap.checkUser.code}">
                    </td>
                </tr>
            </table>
        </div>
        <!--编辑框END-->
    </form>
</div>
<div style="position: absolute;bottom: 0;line-height:40px;width: 100%;border-top: 1px solid #dfdfdf;text-align: center">
    <#if paramMap.isPlhc=='false'>
        <a class="mini-button" iconCls="fa-save" plain="true" onclick="saveData()">发起核查</a>
        <a class="mini-button" iconCls="fa-close" plain="true" onclick="onCancel()">关闭</a>
    </#if>
    <#if paramMap.isPlhc=='true'>
        <a class="mini-button" iconCls="fa-save" plain="true" onclick="plfqhc()">批量发起核查</a>
    </#if>
</div>

<script type="text/javascript">
    mini.parse();
    var form = new mini.Form("form1");
    var startCheckPerson = mini.get("startCheckPerson");
    var startCheckTime = mini.get("startCheckTime");
    var startCheckTel = mini.get("startCheckTel");
    var startCheckPhone = mini.get("startCheckPhone");

    //标准方法接口定义
    function SetData (data) {
        // var o = mini.decode(data);
        // form.setData(o);
        form.setEnabled(false);
        startCheckPerson.setEnabled(true);
        startCheckTel.setEnabled(true);
        startCheckPhone.setEnabled(true);
    }

    window.onload = function () {
        $.ajax({
            url: "/azbj/user/findUserMess",
            type: "get",
            dataType: "json",
            //data: {data: json,prinum: prinum,state: state},
            success: function (data) {
                if (data) {
                    var userMess = mini.decode(data)
                    mini.get("startCheckPerson").setValue(userMess.username)
                    mini.get("startCheckTime").setValue(userMess.nowTime)
                    if (userMess.phone.length == 11) {
                        mini.get("startCheckPhone").setValue(userMess.phone);
                    }
                    mini.get("startCheckTel").setValue(userMess.telphone);
                }
            }
        })
    }

    function saveData() {
        //验证非空字段
        form.validate();
        if (form.isValid() == false) {
            return;
        }

        //校验电话与固话必须输入一个
        var phone = startCheckPhone.getValue();
        var telPhone = startCheckTel.getValue();
        var newPhone = checkTelAndPhone(telPhone,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("手机号码或固话有误，请重填");
            return;
        }
        var data = form.getData();
        var state = 1;
        var prinum = "${paramMap.prinum!''}";
        var json = mini.encode(data);

        mini.confirm("确定要发起核查?","确定?",function(action){
            if (action == "ok"){
                if (mini.get("checkUser").getValue() !== '1') {
                    mini.alert("该户籍地址暂无司法所,请确认");
                    return;
                }
                $.ajax({
                    url: "/azbj/verification/hcstate",
                    type: "post",
                    data: {data: json, prinum: prinum, state: state},
                    success: function (success) {
                        if (success.code == 1) {
                            mini.alert("发起核查成功", "成功", window.CloseOwnerWindow);
                            grid.reload();
                        } else if (success.code == 5599) {
                            mini.alert(success.message);
                        } else {
                            mini.alert("发起核查失败");
                        }
                    }
                })
            }else{
                return;
            }
        })
    }

    /**
     * 批量发起核查
     */
    function plfqhc() {
        //验证非空字段
        form.validate();
        if (form.isValid() == false) {
            return;
        }

        //校验电话与固话必须输入一个
        var phone = startCheckPhone.getValue();
        var telPhone = startCheckTel.getValue();
        var newPhone = checkTelAndPhone(telPhone,phone);
        var flag = newPhone['flag'];
        var kflag = newPhone['kflag'];
        if ('-1' === kflag) {
            mini.alert("请至少输入一个联系方式");
            return;
        }
        if (flag) {
        } else {
            mini.alert("手机号码或固话有误，请重填");
            return;
        }
        var data = form.getData();
        var state = 1;
        var prinums = "${paramMap.prinum}";
        var json = mini.encode(data);

        $.ajax({
            url: "/azbj/verification/plhcstate",
            type: "post",
            data: {data: json, prinums: prinums, state: state},
            success: function (success) {
                if (success.code == 1) {
                    mini.alert("批量发起核查成功", "成功", window.CloseOwnerWindow);
                    grid.reload();
                } else {
                    mini.alert("批量发起核查失败");
                }
            }
        })
    }

    function checkPhone(num) {
        var startCheckPhoneValue = startCheckPhone.getValue();
        var startCheckTelValue = startCheckTel.getValue();
        if (num == '1') {
            if(!validateTel(startCheckTelValue)) {
                mini.alert("固定电话有误，请重填");
            }
        }
        if (num == '2') {
            if(!validatePhone1(startCheckPhoneValue)) {
                mini.alert("手机号码有误，请重填");
            }
        }
    }
</script>
</body>
</html>